﻿using System;
using System.Data;

namespace DAL
{
    public static class DalReportExpenditure
    {
        private static readonly clsConnect Cls = new clsConnect();
        #region[Get-Data]
        public static DataTable GetReportExpenditure(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            return Cls.GetData("sp_Report_Expenditure_Get");
        }
        public static DataTable GetReportExpenditureFillter(string dateBegin, string dateEnd)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@DateBegin", dateBegin);
            Cls.AddParameter("@EndBegin", dateEnd);
            return Cls.GetData("sp_Report_Expenditure_FillterDate");
        }
        public static DataTable GetReportExpenditureEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportExpenditure_ID", id);
            return Cls.GetData("sp_Report_Expenditure_Get_Edit");
        }
        public static DataTable GetReportExpenditureDetailTemp(int usersId)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", usersId);
            return Cls.GetData("sp_Report_Expenditure_Detail_Get_Temp");
        }
        public static DataTable GetReportExpenditureDetailTempSum(int usersId)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", usersId);
            return Cls.GetData("sp_Report_Expenditure_Detail_Get_Temp_Sum");
        }
        public static DataTable GetReportExpenditureDetail(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportExpenditure_ID", id);
            return Cls.GetData("sp_Report_Expenditure_Detail_Get");
        }
        public static DataTable GetReportExpenditureDetailSum(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportExpenditure_ID", id);
            return Cls.GetData("sp_Report_Expenditure_Detail_Get_Sum");
        }
        #endregion

        #region[Insert-Delete-Update]
        public static bool Insert(EtReportExpenditure obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportExpenditure_Code", obj.ReportExpenditure_Code);
            Cls.AddParameter("@Amount_Total", obj.Amount_Total);
            Cls.AddParameter("@DateCreate", obj.DateCreate);
            Cls.AddParameter("@Note", obj.Note);
            Cls.AddParameter("@Lock", obj.Lock);
            return Cls.ExecuteNonQuery("sp_Report_Expenditure_Insert");
        }
        public static bool InsertDetail(EtReportExpenditureDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportExpenditure_ID", obj.ReportExpenditure_ID);
            Cls.AddParameter("@Expenditure_ID", obj.Expenditure_ID);
            Cls.AddParameter("@Lock", obj.Lock);
            Cls.AddParameter("@flag", obj.flag);
            Cls.AddParameter("@Users_Id", obj.Users_Id);
            return Cls.ExecuteNonQuery("sp_Report_Expenditure_Detail_Insert");
        }
        public static bool Update(EtReportExpenditure obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportExpenditure_ID", obj.ReportExpenditure_ID);
            Cls.AddParameter("@Note", obj.Note);
            return Cls.ExecuteNonQuery("sp_Report_Expenditure_Update");
        }
        public static bool Delete(EtReportExpenditure obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportExpenditure_ID", obj.ReportExpenditure_ID);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_Report_Expenditure_Delete", "@Msg");
            return true;
        }
        public static bool DeleteTemp(EtReportExpenditureDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportDetail_Id", obj.ReportDetail_Id);
            Cls.AddParameter("@Expenditure_ID", obj.Expenditure_ID);
            return Cls.ExecuteNonQuery("sp_Report_Expenditure_Detail_Delete_Temp");
        }
        public static bool DeleteDetail(EtReportExpenditureDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportDetail_Id", obj.ReportDetail_Id);
            Cls.AddParameter("@Expenditure_ID", obj.Expenditure_ID);
            Cls.AddParameter("@ReportExpenditure_ID", obj.ReportExpenditure_ID);
            Cls.AddParameter("@Uses_Id", obj.Users_Id);
            Cls.AddParameter("@Reason", obj.Reason);
            return Cls.ExecuteNonQuery("sp_Report_Expenditure_Detail_Delete");
        }
        public static bool DeleteTempAdd(EtReportExpenditureDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", obj.Users_Id);
            return Cls.ExecuteNonQuery("sp_Report_Expenditure_Detail_Delete_Temp_Add");
        }
        public static bool LockUnlock(EtReportExpenditure obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportExpenditure_ID", obj.ReportExpenditure_ID);
            Cls.AddParameter("@Lock", obj.Lock);
            return Cls.ExecuteNonQuery("sp_Report_Expenditure_Lock_Unlock");
        }
        #endregion
    }
    public class EtReportExpenditure
    {
        public int ReportExpenditure_ID { get; set; }
        public string ReportExpenditure_Code { get; set; }
        public DateTime DateCreate { get; set; }
        public float Amount_Total { get; set; }
        public bool Lock { get; set; }
        public string Note { get; set; }
        public int Expenditure_ID { get; set; }
        public int Msg { get; set; }
        public int Users_Id { get; set; }
        public string Reason { get; set; }
    }
    public class EtReportExpenditureDetail
    {
        public int ReportDetail_Id { get; set; }
        public int? ReportExpenditure_ID { get; set; }
        public int Expenditure_ID { get; set; }
        public bool Lock { get; set; }
        public string Note { get; set; }
        public int flag { get; set; }
        public int Users_Id { get; set; }
        public string Reason { get; set; }
    }
}
